package com.mlf.builder.mybatisPlus;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

/**
 * 仅在数据库启用时加载（database.enabled=true）
 */
@Lazy
@Service
@ConditionalOnProperty(name = "database.enabled", havingValue = "true", matchIfMissing = false)
public class PizzaServiceImpl extends ServiceImpl<Pizzamapper, Pizza> implements PizzaService {

    @Override
    public Pizza getPizza(String name, Integer size) {

        QueryWrapper<Pizza> queryWrapper = new QueryWrapper<Pizza>();
        queryWrapper.eq("name", name)
                .eq("size", size)
                .orderByDesc("create_time");
        // 执行查询，未设置数据库，就不执行了
        // return this.getOne(queryWrapper);

        LambdaQueryWrapper<Pizza> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Pizza::getName, name)
                .eq(Pizza::getSize, size)
                .orderByDesc(Pizza::getCreateTime);
        //  实际执行查询并返回结果
        // 示例: return this.getOne(wrapper);
        return new Pizza();
    }
}
